﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using eschoolBO;

namespace ESCHOOL.parents
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        parent par = new parent();
        user_types ut = new user_types();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Panel1.Visible = false;
                DataTable dt1 = ut.GetRecords(-99, "", false, " and ");
                dduser.DataSource = dt1;
                dduser.DataTextField = "user_type";
                dduser.DataValueField = "user_type_id";
                dduser.DataBind();
                DataTable dt = par.GetRecords(Convert.ToInt64(Session["userid"]), "", "", "", "", "", "", "", -99, "", -99, "", "", -99, "","",false, " and ");
                DetailsView1.DataSource = dt;
                DetailsView1.DataBind();
            }
        }

        protected void btnedit_Command(object sender, CommandEventArgs e)
        {
            Panel1.Visible = true;
            DetailsView1.Visible = false;
            DataTable dt = par.GetRecords(Convert.ToInt64(e.CommandArgument), "", "", "", "", "", "", "", -99, "", -99, "", "", -99,"","", false, " and ");
            tbparid.Text = dt.Rows[0]["parent_id"].ToString();
            tbfname.Text = dt.Rows[0]["father_name"].ToString();
            tbmname.Text = dt.Rows[0]["mother_name"].ToString();
            tbfquali.Text = dt.Rows[0]["father_qualification"].ToString();
            tbmquali.Text = dt.Rows[0]["mother_qualification"].ToString();
            tbfoccu.Text = dt.Rows[0]["father_occupation"].ToString();
            tbmoccu.Text = dt.Rows[0]["mother_occupation"].ToString();
            tbaddress.Text = dt.Rows[0]["permanent_address"].ToString();
            tbpno.Text = dt.Rows[0]["phone_no"].ToString();
            tbemail.Text = dt.Rows[0]["parent_emailid"].ToString();
            tbstudid.Text = dt.Rows[0]["student_id"].ToString();
            dduser.SelectedValue = dt.Rows[0]["user_type_id"].ToString();
            tbusername.Text = dt.Rows[0]["username"].ToString();
            tbpassword.Text = dt.Rows[0]["password"].ToString();
            ddquestion.SelectedValue = dt.Rows[0]["security_question"].ToString();
            tbanswer.Text = dt.Rows[0]["answer"].ToString();
        }

        protected void DetailsView1_ModeChanging(object sender, DetailsViewModeEventArgs e)
        {

        }

        protected void btnupdate_Click(object sender, EventArgs e)
        {
            par.parent_id = Convert.ToInt64(tbparid.Text);
            par.father_name = tbfname.Text;
            par.mother_name = tbmname.Text;
            par.father_qualification = tbfquali.Text;
            par.mother_qualification = tbmquali.Text;
            par.father_occupation = tbfoccu.Text;
            par.mother_occupation = tbmoccu.Text;
            par.permanent_address = tbaddress.Text;
            par.phone_no = Convert.ToInt64(tbpno.Text);
            par.parent_emailid = tbemail.Text;
            par.student_id = Convert.ToInt64(tbstudid.Text);
            par.user_type_id = Convert.ToInt64(dduser.SelectedValue.ToString());
            par.username = tbusername.Text;
            par.password = tbpassword.Text;
            par.security_question = ddquestion.SelectedValue.ToString();
            par.answer = tbanswer.Text;
            par.isdeleted = false;
            par.SaveRecords();
            Response.Redirect("~/parents/PProfile.aspx");
        }

        protected void ddquestion_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}
